<?php
	$perpage=30;	
	$pagecount=10;
	
	$msg_deleteone = "Are you sure you want to delete the selected item?";
	$msg_ask_select = "Please select at least one of them!";
	$msg_conf_del = "Are you sure you want to delete the selected items?";	
	$msg_name_exists = "Sorry! This list name already exists in database. Please input another one.";
	
	$lb_tottalrow = "Total records: ";
	
	$patterns = array(' ','`','~','!','@','#','$','%','^','&','*','(',')','_','+','=','|','\\',"'",'"',':',';','.',',','?','>','<','/','®','™','é','è','â','à','ê','û','ë','ç','ô', "’", '“','”');
	$replacements = "-";
	
	$lower = array('á','à','ả','ã','ạ','â','ấ','ầ','ậ','ẩ','ẫ','ă','ắ','ằ','ặ','ẵ','ẳ','ẻ','è','ẹ','é','ẽ','ê','ế','ề','ệ','ể','ễ','ô','ố','ồ','ộ','ổ','ỗ','ơ','ớ','ờ','ợ','ỡ','ở','ò','ó','ỏ','õ','ọ','ư','ứ','ừ','ự','ữ','ử','ị','ì','í','ĩ','ỉ','ý','ỳ','ỵ','ỷ','ỹ','ù','ú','ụ','ũ','ủ','đ','Á','À','ả','Ã','Ạ','Â','Ấ','Ầ','Ậ','Ẩ','Ẫ','Ă','Ắ','Ằ','Ặ','Ẵ','Ẳ','Ẻ','È','Ẹ','É','Ẽ','Ê','Ế','Ề','Ệ','Ể','Ễ','Ô','Ố','Ồ','Ộ','Ổ','Ỗ','Ơ','Ớ','Ờ','Ợ','Ỡ','Ở','Ò','Ó','Ỏ','Õ','Ọ','Ư','Ứ','Ừ','Ự','Ữ','Ử','Ị','Ì','Í','Ĩ','Ỉ','Ý','Ỳ','Ỵ','Ỷ','Ỹ','Ù','Ú','Ụ','Ũ','Ủ','Đ');
	$lowerno = array('a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','e','e','e','e','e','e','e','e','e','e','e','o','o','o','o','o','o','o','o','o','o','o','o','o','o','o','o','o','u','u','u','u','u','u','i','i','i','i','i','y','y','y','y','y','u','u','u','u','u','d','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','e','e','e','e','e','e','e','e','e','e','e','o','o','o','o','o','o','o','o','o','o','o','o','o','o','o','o','o','u','u','u','u','u','u','i','i','i','i','i','y','y','y','y','y','u','u','u','u','u','d');
	
	
	function listProductCat($index, $id, $level, $maxlevel, $id_index)
	{
			$str = "";
			for($i = 0; $i < $level ; $i++)
				$str .= " &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ";
			$db = new MySQL();
			
			$sql = "select * from product_cat where parentid = '$id' and level <= $maxlevel and id != '$id_index' order by parentid, orderId asc ";				
					
			$rst = $db->select($sql);				
			while($lo=$db->fetch($rst))
			{		
				$option .="<option value=";
				$option .=$lo['id']; 	
				 if (isset($index))
				 {
					if($index == $lo['id']) $option .= " selected ";
				 }
				 if (isset($parentid))
				 {
					if($parentid == $lo['id']) $option .= " selected ";
				 }			
				$option .=">".$str.$lo['title'];
				$option .="</option>";
				$option .= listProductCat($index, $lo['id'], $lo['level'], $maxlevel, $id_index);					
			}
			
	
		return $option;
	}
	
	function listProductCat_Item($index, $id, $level, $maxlevel, $i_type)
	{
			$db = new MySQL();
			
			$sql = "select * from product_cat where parentid = '$id' and level <= $maxlevel order by parentid ";				
				
			$rst = $db->select($sql);				
			while($lo=$db->fetch($rst))
			{										
				$str = "";
				for($i = 0; $i < $level ; $i++)
					$str .= " &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;";
				if($lo['level']!=1)	$str .= " --> ";
				
				
				$option .="<option value=";
				$option .=$lo['id']; 	
				 if (isset($index))
				 {
					if($index == $lo['id']) $option .= " selected ";
				 }
				 if (isset($parentid))
				 {
					if($parentid == $lo['id']) $option .= " selected ";
				 }			
				$option .=">".$str.$lo['title'];
				$option .="</option>";
				
				$option .= listProductCat_Item($index, $lo['id'], $lo['level'], $maxlevel, $i_type);					
			}
			
	
		return $option;
	}
        
        function listNewsCat_Item($index, $id, $level, $maxlevel, $i_type, $table="news_cat")
	{
			$db = new MySQL();
			
			$sql = "select * from $table where parentid = '$id' and level <= $maxlevel order by parentid ";				
				
			$rst = $db->select($sql);				
			while($lo=$db->fetch($rst))
			{										
				$str = "";
				for($i = 0; $i < $level ; $i++)
					$str .= " &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;";
				if($lo['level']!=1)	$str .= " --> ";
				
				
				$option .="<option value=";
				$option .=$lo['id']; 	
				 if (isset($index))
				 {
					if($index == $lo['id']) $option .= " selected ";
				 }
				 if (isset($parentid))
				 {
					if($parentid == $lo['id']) $option .= " selected ";
				 }			
				$option .=">".$str.$lo['title'];
				$option .="</option>";
				
				$option .= listProductCat_Item($index, $lo['id'], $lo['level'], $maxlevel, $i_type, $table);					
			}
			
	
		return $option;
	}
	
?>